import { userProfilesAPI } from "@/request/api";
export default {
  namespaced: true,
  state: {
    cartTotal: 10,
    userInfo: {
      headImg: require("../../assets/img/userImg.f8bbec5e.png"),
      nickName: "--",
      coin: "--",
    },
  },

  mutations: {
    updateUserInfo(state, payload) {
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo;
    },
    initUserInfo(state, payload) {
      state.cartTotal = 10;
      state.userInfo = {
        headImg: require("../../assets/img/userImg.f8bbec5e.png"),
        nickName: "--",
        coin: "--",
      };
    },
  },
  actions: {
    async asyncUserInfo(context) {
      // 异步发送请求
      let uRes = await userProfilesAPI();
      // console.log("用户信息", uRes);
      // 更新用户信息
      await context.commit("updateUserInfo", uRes.data);
    },
  },
};
